Received: by 2002:a89:48b:0:b0:1f5:f2ab:c469 with SMTP id a11csp1415258lqd; Thu, 25 Apr 2024 15:12:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVAG00QLtPZCQR8Lc+D5/+FG4Ek1/49YG0Dug67tYGB71xzEdpxL8Sa+eZV/YJErvqwfds2Q9jXYP1wO3yS4OtDEnlHJzn3D4+bL9qsUQ== X-Google-Smtp-Source: AGHT+IEH3oMKijgVtFRSK4ZtW337yeFJY941YagC7KhCw3zKs8uK3i6wYTsinTiOHwIQ3JtZ2fIc X-Received: by 2002:a05:622a:304:b0:439:ef73:2e47 with SMTP id q4-20020a05622a030400b00439ef732e47mr929042qtw.8.1714083129697; Thu, 25 Apr 2024 15:12:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714083129; cv=pass; d=google.com; s=arc-20160816; b=TAEtsj9frfV6/vXYeyiKAmBZ6bwgM95tJ8MBO7XvUf81WxZ4kByxPOhuV/YT2rOM5W IQl8rsanz8i8yK5aXA3EnyJmwVabPaaLFPGQNNEcnZNBWb4htymj/IosbUUi7Z9jq2ht yptv67M9Zlq9LpeWkBZ7qA10phydxnAftME1krJ1HDxxFrYOjfbBDCd/cHdRC2g7GQS3 PTUrP13WxUNqhvvJjdpQumPwJBsG/prVU8mh6/fw2Wx8IRga3KACCNWHbjC2cZFsFl0l MRjW8GQuM5AKsPXw99g6LRL7+cLMPbSqzr6vYx2s+oIPYc+Pveh2mf6C545ruyzFaCKZ +5pw== 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=WybF+hwD9jFitffFOqbw8SwR2/4xAqr74645NwJ+ic8=; fh=RRkWXDrutj1Lx3gPsKtVf+Be2JiZ2wU9Kn2QA5PRRrs=; b=ya2yx7XNGYtRuzz+4Jan8lhc/1HcGc+MIB8lqsj2EPpKUflf7PFcsYysY11PDxWH7m sYQD+y+jxH7cLA4NuLZZ7a/6P7KpE3dU1d91mVg20JeMKEmH5PXK6BkxAC0v1ckeucqe n41wS/UwtcfMpFlzDf3U6NvUTwoSISpq6f4NU9TEZCxyJ1CjZlE7irg4zfCT7IhxzDaX QR0WAUaG1anknHvd8LU7Ccu4BJGygnY064XrH2MiVcDRdmmGKruXonT+Xalbjve2bYvw HrTXq5MTzimQRvD1ChgDf+FFzcxPJ0/iAruV0u8UvBJI2RbtaC3idb9uSUB0MPqZ5nB4 qaeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=i7P0PYrr; 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-159300-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159300-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 dj22-20020a05622a4e9600b004347d9f0ed0si16717498qtb.569.2024.04.25.15.12.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 15:12:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-159300-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=i7P0PYrr; 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-159300-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-159300-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 6C6FF1C208A0 for ; Thu, 25 Apr 2024 22:12:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 525BB15665C; Thu, 25 Apr 2024 22:07:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="i7P0PYrr" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.15]) (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 5A1FD156242; Thu, 25 Apr 2024 22:07:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082835; cv=none; b=WkY7liyaNs0CEANJa9UechP17Ed6DRKmv4ypHg+7AiAyh2OTbwi06e3MyJ+quNgN57CcxaqrIB+5Ayg4ABQE7iRd8Lm98hc6MsxuDwVku8atdHN36fBkxWKuL88H6Rlr0+CNJc3qzLKv/MShlZxgmpfVFRkDnpbTQsKzfOctg+8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714082835; c=relaxed/simple; bh=1qDixauO6x0Pyd9QSSsnF1wJukXfiH4Aj2/qUYukcgg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pgQVYTrM9U1ApNMlexiAeFYdPZJUMqfrdolAVxUTSiZ+BBKg5EVSlfSmTukMcYxcHBExtcKKGqOuZh3m21dZ6Gu2SnlsGaRQnePEWyYO+RcOpXbVj/0MET++7TsIF/wbmk39aZwrdJ61qXZtS8T9F0FMMAoilUspcckKmhf//9s= 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=i7P0PYrr; arc=none smtp.client-ip=198.175.65.15 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=1714082833; x=1745618833; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1qDixauO6x0Pyd9QSSsnF1wJukXfiH4Aj2/qUYukcgg=; b=i7P0PYrrt8zMEnHgMolHBrGNC/KrDc6f2kQGNdyd4FMiXzGvpo5oJrYj 3aaOx2RHgtPZC67sL3CDp2Pin9Yb7qBzkjM1OyHhJPxh79h2nzk4U9mPD e2w99tnrHxY44yvIi6l+oWBdClWlhl/CJ79dYa7vsEB0m3VVw50ec66+y j92KcHxceK6IZoOsJqL44mwP6C+yH/CszZQGPj5LrClugGPmrTBeBfmjx glOkX0GBMFcaPfrHm4rY2dVJB9GBZjNSpNo0nwD3Al4ePUECwTOWV7e8w QqBRdHWYyib5yNVOsHbInyx+oBIuZwvdancyRceF9h7vBWX0oXtKdXDU9 w==; X-CSE-ConnectionGUID: c/dSdYIWRqSLNBEppRiUSQ== X-CSE-MsgGUID: GElXD7oXRyKGZN5sOmlATQ== X-IronPort-AV: E=McAfee;i="6600,9927,11055"; a="13585398" X-IronPort-AV: E=Sophos;i="6.07,230,1708416000"; d="scan'208";a="13585398" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa107.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2024 15:07:11 -0700 X-CSE-ConnectionGUID: oawdXQ3fTtWsBkoUVQFeSg== X-CSE-MsgGUID: JobcZGFiTgObl/H5GHSx/Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,230,1708416000"; d="scan'208";a="25185083" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Apr 2024 15:07:12 -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 V5 1/4] KVM: x86: hyper-v: Calculate APIC bus frequency for Hyper-V Date: Thu, 25 Apr 2024 15:06:59 -0700 Message-Id: <76a659d0898e87ebd73ee7c922f984a87a6ab370.1714081726.git.reinette.chatre@intel.com> 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