Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp72216lqh; Mon, 6 May 2024 11:36:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUm/PlKCAnX6fjekvY5KqiUZbGFwyzcVcDd7ZUiZZPCYoyqxYD7OmVOQZLf+NAOkj9YQsCDUEP+Gu9yjgPC3516plNZf8Wpveq/MyMJ1A== X-Google-Smtp-Source: AGHT+IFqKtYE9IhY4gwAznG+RTS4N9yvLhOj7AS21gajda6qawi2cyNBKZt4klCxX0Rz/mO/8Pjv X-Received: by 2002:a17:906:730d:b0:a59:c52b:9937 with SMTP id di13-20020a170906730d00b00a59c52b9937mr3383657ejc.4.1715020607216; Mon, 06 May 2024 11:36:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715020607; cv=pass; d=google.com; s=arc-20160816; b=eT2+B0TmChkGb2WmVwywfli+AqdaQI2CMM7xfIYV2BCKZijEKL0b1GxQ31/RabwQzf kdTGU6Z+mmzlP5dxUOKNDDGj3j2/9A3xCo1kpvls8RMvnYwaQrEizxICMK9LuvTHSKmo 5k1XvwfQvJL+ezLUOgCvganzBbcxKuv3AUlaitCUBgL6GxafqvwNWSqBYXkoZ/ei2GLC HaLPjUAR+l+/8SFY4uAdiVDvE+bEM4f0JVVrqUYhRXeFaZRbi3jevAWL/ZIfh8mH0Bfk TedpynYw8NgQYANUmhlKILsNRFmo10xbeUm5LFo7E0MOsu5MvwBAAE+D0MnbXcBh/KzR 8mlw== 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=p5BBGmOaPx+yuaTlUkTr01i4MPBmRpEKT/mGIks7+zE=; fh=39c7xHRXKGHRweehzLnY8wn6iHFCUfmQLOpmt3ijdwY=; b=DmsrSkv+Wr3zpB1b+8ZNmYgxv+2JmFtVWb+RvyT8tsRFTaCbbsrZC6Weqi8ukqDAo3 ihFcY0LYHgpAKNOwlm1HbtYpqjbBktbUUfkvGfGuwvzULwIliFlxHTV4qn0W5LsQHFpT DDMOSMWRgnWynNjMI23Y4W2tjiLYI6iaWSCTtYShQZifyDQnfF1b1cx0vwaF+sSKjsu2 jgtkyaKWYXxIDa8mlFWHMepQksvOrjrL2G6XZ6uYXXgDS5NzEwCG+DRn7vTYwfM+Mszq Hm8CR0T3BZe0Utz7bmPszaqZYDTN+A9i8kJY/c1AzYlPNMgTuOKVkB8sRKkJOMgXN7hu ubHw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Eb6HrA0+; 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-170297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170297-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ca3-20020a170906a3c300b00a59a3efadb6si3190637ejb.109.2024.05.06.11.36.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 11:36:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=Eb6HrA0+; 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-170297-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170297-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 am.mirrors.kernel.org (Postfix) with ESMTPS id EB1591F237E2 for ; Mon, 6 May 2024 18:36:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 44541158DD5; Mon, 6 May 2024 18:36:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Eb6HrA0+" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) (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 8C1B013E8BA; Mon, 6 May 2024 18:36:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.9 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715020586; cv=none; b=qFO32/aZMUZqMDs4edVxmS2GSWEdqThQ1N09idqoeQb4FDnxSJjG2TR+sfWNaGVkU97cVGzAY2LPl5tKTGXeWNIfMh3f3i8naBjFkaTZjCd1GJszwwn7J72YMYVW68oJd1dMHWis6LfcQB5g8QqRqVWoKBUboZRZFR24jrklQUI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715020586; c=relaxed/simple; bh=JCMdLmx7hIlCtOWjHewphvGoWCSoaO1qN1Iyo0V0rtg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=P/VM63ooTNJDRfxb1QtVGalRRE364RlInmva6CWASj0b2REvMEi3mlAo5zRcijC0GeZ75CKk/ZOBtOGJAslF+n/yzBf29IdbF7s+yQtBh0K2Y4wfmCcK8+3DyBX1T1/aGJmqlo/O/AK9jKxOYimzUZJFTKqx/EosK4wDrjhPKGU= 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=Eb6HrA0+; arc=none smtp.client-ip=192.198.163.9 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=1715020585; x=1746556585; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JCMdLmx7hIlCtOWjHewphvGoWCSoaO1qN1Iyo0V0rtg=; b=Eb6HrA0+IVyp2sJhunKku6pJQbRR8xrl6Zgg7zCxqAwO5heq2Acf35QT wHnNLZ3LCkXhoIVTSlKu7agTZW95+2DvlaloTIAiCwJ1XeMya/FrS0CGc FlYUEu6Rrt48ogIfaq3CUkO/TmyodNYDyAxeJyjYelKjmJ5SdMa+EyMxv ymPfugqjKoqzAIQP9bvOEWP6ksEpdi7MQ3Z9PDbnxsID3pa/21J5SdbRg JQVBXhAaANKSnlxdALmVsaq4Fgll4CBlkOiO3IKP9Awih/tXxCyG/1DkC BegSd5YHSZZbjiE1MShVUyaSDTz5yAygonYBDPGd55v1hVdVj3jdPOb+E w==; X-CSE-ConnectionGUID: N5Fd4vAISRSm7VWeB3aOkA== X-CSE-MsgGUID: aKYfLx+TTbuy/Lgx8zaQ9w== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="21455743" X-IronPort-AV: E=Sophos;i="6.07,259,1708416000"; d="scan'208";a="21455743" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 11:36:10 -0700 X-CSE-ConnectionGUID: Dl22qp/lSiOB0TYBDYy6EA== X-CSE-MsgGUID: bStAaS47SbybSrCM0oz2qw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,259,1708416000"; d="scan'208";a="28237805" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 11:36:09 -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, yuan.yao@intel.com Cc: reinette.chatre@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V6 1/4] KVM: x86: hyper-v: Calculate APIC bus frequency for Hyper-V Date: Mon, 6 May 2024 11:35:55 -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 Reviewed-by: Rick Edgecombe [reinette: rework changelog] Signed-off-by: Reinette Chatre --- Changes v5: - Add Rick's Reviewed-by tag. 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