Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp596615lqp; Thu, 21 Mar 2024 09:48:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWkOOxlDtDfUeuKv6letRjCYdktUP6JawwC1AYTwplU2WdbZJLzYtrnrnA1/MErBiMKoaznh5RSTmv4ulc066GKN5lr/KcGnhyi9hw6lg== X-Google-Smtp-Source: AGHT+IE+so/pzQWzXL4TvSmXmLNHiUN2lbmzZBzyg+h0t9UfsKsILcfnwFBTm5EujGyI7jBsAnlC X-Received: by 2002:ac8:5dce:0:b0:430:e9fc:f21a with SMTP id e14-20020ac85dce000000b00430e9fcf21amr9622163qtx.17.1711039686440; Thu, 21 Mar 2024 09:48:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711039686; cv=pass; d=google.com; s=arc-20160816; b=nkPqdDPx1QUSp5hQlA48nSVTKOSmNq+hYmLno1uYGK+lr1YkRIGElF/cOIuU/xZH6P BfOAXLA4qlt6M7bdhPfu7bJwzpXh5L+VYPKbpMhgyfdPyiOx+vmNS35kneYd7o4CkiBU UIl4mTDDEYzoCWCmj2xlEvB2kR+RoZKZ5rAFvcmBB+f3S3CVmsNwOfO1t2qJlDdWROom EM8CfqJubefhuAPqdjG4Tsru0tuxeVxS6wVqRdXN63yGkqpCeU3Qb7TwSKBNPoVe6Bmu sWeehM9uKQIydMuS1uF5tS6/xvcghICoAVJPd0n/HCl5z1Of+J+qpQjizR8czMqQqRIl FeNg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ueq4VT+ikNbFoU1u9mpc7dYOciAGX0dFgyj4wChET2M=; fh=RRkWXDrutj1Lx3gPsKtVf+Be2JiZ2wU9Kn2QA5PRRrs=; b=dACKSDRCgEogfsljrjoKIp5XqudZXgIl2hZ9iQuk6DV+HarIu4VH6/XAeDXoiLqexx ydcVf7pkHkFXXt4RuiQ7NfOQigealcWSgiMBYqwrD+SshPiLIpog1WT3ufwmpMJ5uC2R Kb2vRroMRdxphleoGPQ1mbMZyEk+55h4McEJDj/I8OSoraQmDRr8D162NM4pJM0my3ZU qAyQKCLcKYlXUYOEMNkKyTYnGbSTUDUPnmZtl5L6DU1g4P8BCJAHeezx5pUG5VLOdrkh 9ianUq8kcOQJleVm2fX3Tpmg3LNYnjQfT/csd8TxBlvaCez/+BqFQ8zAlt1g3a9sfc8j GYBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NhVoykaB; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-110383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110383-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id n7-20020a05622a040700b004311ff92b26si83477qtx.207.2024.03.21.09.48.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:48:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=NhVoykaB; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-110383-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110383-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2CE501C21151 for ; Thu, 21 Mar 2024 16:48:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8DEAC13F423; Thu, 21 Mar 2024 16:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="NhVoykaB" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2D6113B79F; Thu, 21 Mar 2024 16:38:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039087; cv=none; b=O9ewMgu5TuKo6cEBhu+A52MdQUehIu4uB09KmWbJHPJ5TtW5f+YC4TsIp40KDHjLOEw+OrebB1Ltzz7oRRGYLS95Ahj4GvmMksPl+qWHOtr8Qf8KIUFYOVXrX/DOVkCuJbKdmWuAr0qO7Udd6BrVlZLmQgp9iDpqLGFH+pRzO3I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711039087; c=relaxed/simple; bh=P64UvqIPLZQFjj6ReZTc/GZtsS5RNgqfl1B0Cn1kB+g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ppx/KA+9yS8fbz7+Okc4TXOJpiw7fZ2sWpCwfT/YncZGE1QFbvgvu6ignB2OycfFYkqwph1nXU3SOiWeKNLChVEEVqNX+z2pH0R7loD/PbguxlHpFhUwlqvZyOHALJweCkEE723kHIMbjej/rv3SUxqc0s20Nz+W0EzXRc1EBSA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=NhVoykaB; arc=none smtp.client-ip=192.198.163.7 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1711039085; x=1742575085; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=P64UvqIPLZQFjj6ReZTc/GZtsS5RNgqfl1B0Cn1kB+g=; b=NhVoykaBhIhrkuoNWa9CUraltWqAPrnSriM39Rb5rard1Ef/AevNu6PS Rwwd6CAWj5pZcxrMmOSeV/QBZmLVhdopQ97dtkbkiOmJfaMGE0KF1aDwk ohx8S8qyl1auDj3vJxjNQFESJJp+T+bX62hOYXz4E0geqFnaeImwef0uB 0qJ0hjnr1swvFgB3ghGW0sI0H5g/1XAVIiw8X+/N6/DCbtGfIpg9XtEz+ 8CPv3Vz2FP9HsB708PrhbgZu+/E5SdPXbpqidtAzPl4QdF74k/Gb6sdmj MgyC1xJ0750ahqrl5L5V7dnPhbZPB4gmtzGS6eezHc1ijgAyxs0NtWhoi Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11020"; a="31477562" X-IronPort-AV: E=Sophos;i="6.07,143,1708416000"; d="scan'208";a="31477562" Received: from orviesa003.jf.intel.com ([10.64.159.143]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 09:37:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,143,1708416000"; d="scan'208";a="19280010" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by ORVIESA003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Mar 2024 09:37:58 -0700 From: Reinette Chatre To: isaku.yamahata@intel.com, pbonzini@redhat.com, erdemaktas@google.com, vkuznets@redhat.com, seanjc@google.com, vannapurve@google.com, jmattson@google.com, mlevitsk@redhat.com, xiaoyao.li@intel.com, chao.gao@intel.com, rick.p.edgecombe@intel.com Cc: reinette.chatre@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V4 1/4] KVM: x86: hyper-v: Calculate APIC bus frequency for Hyper-V Date: Thu, 21 Mar 2024 09:37:41 -0700 Message-Id: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Isaku Yamahata Remove APIC_BUS_FREQUENCY and calculate it based on nanoseconds per APIC bus cycle. APIC_BUS_FREQUENCY is used only for HV_X64_MSR_APIC_FREQUENCY. The MSR is not frequently read, calculate it every time. There are two constants related to the APIC bus frequency: APIC_BUS_FREQUENCY and APIC_BUS_CYCLE_NS. Only one value is required because one can be calculated from the other: APIC_BUS_CYCLES_NS = 1000 * 1000 * 1000 / APIC_BUS_FREQUENCY. Remove APIC_BUS_FREQUENCY and instead calculate it when needed. This prepares for support of configurable APIC bus frequency by requiring to change only a single variable. Suggested-by: Maxim Levitsky Signed-off-by: Isaku Yamahata Reviewed-by: Maxim Levitsky Reviewed-by: Xiaoyao Li [reinette: rework changelog] Signed-off-by: Reinette Chatre --- Changes v4: - Modify subject to match custom: "KVM: x86/hyperv:" -> "KVM: x86: hyper-v:" and use standard capitalization for Hyper-V ("hyper-v" -> "Hyper-V"). - Rework changelog to remove pronouns ("we"). - Change logic in commit log: "APIC bus cycles per NS" -> "nanoseconds per APIC bus cycle". - Fix typos. (Maxim and Xiaoyao) - Add Maxim and Xiaoyao's Reviewed-by tags. - Add Maxim's "Suggested-by". Changes v3: - Newly added according to Maxim Levitsky suggestion. arch/x86/kvm/hyperv.c | 2 +- arch/x86/kvm/lapic.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/hyperv.c b/arch/x86/kvm/hyperv.c index 8a47f8541eab..1030701db967 100644 --- a/arch/x86/kvm/hyperv.c +++ b/arch/x86/kvm/hyperv.c @@ -1737,7 +1737,7 @@ static int kvm_hv_get_msr(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata, data = (u64)vcpu->arch.virtual_tsc_khz * 1000; break; case HV_X64_MSR_APIC_FREQUENCY: - data = APIC_BUS_FREQUENCY; + data = div64_u64(1000000000ULL, APIC_BUS_CYCLE_NS); break; default: kvm_pr_unimpl_rdmsr(vcpu, msr); diff --git a/arch/x86/kvm/lapic.h b/arch/x86/kvm/lapic.h index 0a0ea4b5dd8c..a20cb006b6c8 100644 --- a/arch/x86/kvm/lapic.h +++ b/arch/x86/kvm/lapic.h @@ -17,7 +17,6 @@ #define APIC_DEST_MASK 0x800 #define APIC_BUS_CYCLE_NS 1 -#define APIC_BUS_FREQUENCY (1000000000ULL / APIC_BUS_CYCLE_NS) #define APIC_BROADCAST 0xFF #define X2APIC_BROADCAST 0xFFFFFFFFul -- 2.34.1