Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp574703rdb; Fri, 26 Jan 2024 04:42:43 -0800 (PST) X-Google-Smtp-Source: AGHT+IESX1gpVumLc0hgKmtfXtwdu5gcYHTSGjAQmIhq5Y6P8s82Xu4vyoVwLhPHR/8Qz6a4HP1X X-Received: by 2002:a05:6358:98a8:b0:176:ae9c:34bc with SMTP id q40-20020a05635898a800b00176ae9c34bcmr1603634rwa.61.1706272962729; Fri, 26 Jan 2024 04:42:42 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706272962; cv=pass; d=google.com; s=arc-20160816; b=T1bJ421KLJ7Yv9LTgVrX0N1Np6FbvR58HSE8Q6pSQ1OQr3e1qE7kAqMjP2DWCbHFqg wWzEqp69fqOzzFzM9e9ytO7slDc1ZhCHUdyfQBZV9uvTU+wAUEDImyC0/tf+j/+4VlYZ 61s3NLIDmdIdxJQjIcXZSeZaJykWSTBi7ZB8A95crvGk31Ad2rPKTScJ/dLmY1kRXkUw PSF0NmEwkcWM0DTdR3Bq0dhrsRb+4ojT55B0/bnfOstuyk8fP+3lGXeuEvQrlThQ7xD8 A8Hu2cg+Wge7nGKdMg+NMCQNcLZRMyGz2asQs6nXQj3NPFAD7i0LlgSBAmyN+pxnTzZQ Q/oQ== 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=nyUy5uJK+Nk3poPGuMh1oFrNr53PSwWJkoGEZFq9ptg=; fh=ILHfJ0uLc1EruXziwgJ5p79BI7cXVVRZxn5LqOC7zKA=; b=FS/0SwDOZQBBFFwMxAmcbOB4PRu7QgxGANkYRpaSnlSI94mEuSzTEjJ91veEmwXDnS QQrordF3oIkh5mueqjhq5OnSp1MHZed9qIPHjQElUscuo9zAOiC5X3nD5vQi+HlWA/Zg /Qjl36BQ1YSwUtxNK9DyzTa6bvY4KH7wQqSO8jdrj8C0mkJ04z46O96UU1cPjdbz4da8 8PfIpjZLq8Gz6iZbLvY0klwph4IxBYZtFGkucWUYLITR9gcse0ucMX2xbElkND8m3lHM Zxt8mVwgvjddIRtRYA2Z3ImkgzUip57U+sJKxtkqyaGG5xXzMeQQPDWJ9d2cXGHyTWDE LN5g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RodnbQRQ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39833-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39833-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y194-20020a62cecb000000b006dde26c600asi1121681pfg.104.2024.01.26.04.42.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 04:42:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39833-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=RodnbQRQ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39833-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39833-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id C61F5B2B147 for ; Fri, 26 Jan 2024 09:38:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 13ADC145342; Fri, 26 Jan 2024 08:57:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="RodnbQRQ" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) (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 BEFF5144628; Fri, 26 Jan 2024 08:57:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706259429; cv=none; b=JxAsW/b6D0bNDDQwoUpjunfr4UaRWBVY9HCKBVlfoTycQDjdKuZEgzQO3gjZ+nWKbAsAxZEbOgICjIj38frTextu/TaRtRWBTr/Nd2n+HHo33i/nevdSYR4NOjpAcUtOcdHi9TuZIosbwlxEtKaAhxggC73PxTgFW4ll+vOeWeg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706259429; c=relaxed/simple; bh=33GvgNSc67Y43IDULKlxZdH1EO3byZjhBrpeli7mbiQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VkkKOjDksMQz8c727XkZpxepxeFqFgk1m76nHJvpUWSup771BR4Wf7fvRf/3IAqYzgR61HTGJyiPCMDwsMk65MxwkjkFbSaO5hCLx3VCwJMiAu+sM8NFXRbOCsTvzMJg2960g3WmLPFtPoR7sMT+RH9NU6esrEhivD9FojRlhEo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=RodnbQRQ; arc=none smtp.client-ip=198.175.65.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1706259428; x=1737795428; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=33GvgNSc67Y43IDULKlxZdH1EO3byZjhBrpeli7mbiQ=; b=RodnbQRQ9rRy8YJRaAF998vTCHvwgFxcLj0VwAmek3SZNVjAdWdiBxgF RReNHthqhoWz1654EwRMEMH9YIA0JndvRANCOhE2DHxAxPI1+zSyQSQXy VTd4E/gLcNSoTfaI2o9WEH3ARxcvtg+WCQ+9CgZsvpAbTEzjOC3FyXeGv aTVRh3GLMpreXzEKpdTdJhXivPeJK7Y5lEwBK90n5jnCSM+uOu7cLZdPP oDbL5JTPk2pi/RE7ja0ef0vHORZYV6nRlZ5rE4HegBYQhVJiHralP/meI XZgLMfm+6PTAxH61IaCGXY7i933UTDS6wfNFRqgbaLoc3PMawjWuMd/BZ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="9792596" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="9792596" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2024 00:57:07 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="930310100" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="930310100" Received: from yanli3-mobl.ccr.corp.intel.com (HELO xiongzha-desk1.ccr.corp.intel.com) ([10.254.213.178]) by fmsmga001-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Jan 2024 00:57:02 -0800 From: Xiong Zhang To: seanjc@google.com, pbonzini@redhat.com, peterz@infradead.org, mizhang@google.com, kan.liang@intel.com, zhenyuw@linux.intel.com, dapeng1.mi@linux.intel.com, jmattson@google.com Cc: kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, zhiyuan.lv@intel.com, eranian@google.com, irogers@google.com, samantha.alt@intel.com, like.xu.linux@gmail.com, chao.gao@intel.com, xiong.y.zhang@linux.intel.com, Xiong Zhang Subject: [RFC PATCH 18/41] KVM: x86/pmu: Intercept full-width GP counter MSRs by checking with perf capabilities Date: Fri, 26 Jan 2024 16:54:21 +0800 Message-Id: <20240126085444.324918-19-xiong.y.zhang@linux.intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240126085444.324918-1-xiong.y.zhang@linux.intel.com> References: <20240126085444.324918-1-xiong.y.zhang@linux.intel.com> 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: Mingwei Zhang Intercept full-width GP counter MSRs in passthrough PMU if guest does not have the capability to write in full-width. In addition, opportunistically add a warning if non-full-width counter MSRs are also intercepted, in which case it is a clear mistake. Co-developed-by: Xiong Zhang Signed-off-by: Xiong Zhang Signed-off-by: Mingwei Zhang --- arch/x86/kvm/vmx/pmu_intel.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/vmx/pmu_intel.c b/arch/x86/kvm/vmx/pmu_intel.c index 7f6cabb2c378..49df154fbb5b 100644 --- a/arch/x86/kvm/vmx/pmu_intel.c +++ b/arch/x86/kvm/vmx/pmu_intel.c @@ -429,6 +429,13 @@ static int intel_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) default: if ((pmc = get_gp_pmc(pmu, msr, MSR_IA32_PERFCTR0)) || (pmc = get_gp_pmc(pmu, msr, MSR_IA32_PMC0))) { + if (is_passthrough_pmu_enabled(vcpu) && + !(msr & MSR_PMC_FULL_WIDTH_BIT) && + !msr_info->host_initiated) { + pr_warn_once("passthrough PMU never intercepts non-full-width PMU counters\n"); + return 1; + } + if ((msr & MSR_PMC_FULL_WIDTH_BIT) && (data & ~pmu->counter_bitmask[KVM_PMC_GP])) return 1; @@ -801,7 +808,8 @@ void intel_passthrough_pmu_msrs(struct kvm_vcpu *vcpu) for (i = 0; i < vcpu_to_pmu(vcpu)->nr_arch_gp_counters; i++) { vmx_set_intercept_for_msr(vcpu, MSR_ARCH_PERFMON_EVENTSEL0 + i, MSR_TYPE_RW, false); vmx_set_intercept_for_msr(vcpu, MSR_IA32_PERFCTR0 + i, MSR_TYPE_RW, false); - vmx_set_intercept_for_msr(vcpu, MSR_IA32_PMC0 + i, MSR_TYPE_RW, false); + if (fw_writes_is_enabled(vcpu)) + vmx_set_intercept_for_msr(vcpu, MSR_IA32_PMC0 + i, MSR_TYPE_RW, false); } vmx_set_intercept_for_msr(vcpu, MSR_CORE_PERF_FIXED_CTR_CTRL, MSR_TYPE_RW, false); -- 2.34.1