Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp488478rdb; Fri, 26 Jan 2024 01:32:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IE1nhz0AFr7eiyd9ts7rstBBKBkr3Bp3fiR+uEkv66sn03D0kggqckoAT6aL5FJbtFj1Zz/ X-Received: by 2002:a05:6808:138c:b0:3bd:e8f6:5a3 with SMTP id c12-20020a056808138c00b003bde8f605a3mr523329oiw.18.1706261545675; Fri, 26 Jan 2024 01:32:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706261545; cv=pass; d=google.com; s=arc-20160816; b=AXJBhr7LZrjndpUoCwDZ7w0UW7g+vjEwbbu3LAnUaRZMwJV+G+k+4GpDZOZvkTsMQh Nujy4Ymszy+aMbMR+dkEa7v6MUMkECc/Q9Lsvv1qvhQ1Land3+rzPUSh8yy4UPtPIlHT R/38JqwpbJBMYZyRGXNAQ4Xbrpc1JqoQefXUQ40jqGNuMe4fEuf6Lxo0BEuC5z/Rj7rF J+ZkuIjzcJuN6+qZw0WCxNw35f7dLyGwbwyd05DamERonJcQPTZLYJ2Nx7vM38/Pdm+M 0Rvdpc10DhR8cGwlKUYXSdlgegl4qjraqrbdT4AxvBDNMYRoHjwXGpwbFIlMet7EfW/5 aSmQ== 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=eAdyAfQiFLbigv59d2WPxqtmVZVg1g6gS6M0SYa/g08=; fh=ILHfJ0uLc1EruXziwgJ5p79BI7cXVVRZxn5LqOC7zKA=; b=mEOcgWTiSlaKXmawZacN5J2YSIonHwkwFPAXxwM9kX+Wo99EP2yI+VQ2u1tlaKYHaU ZirP8QXsf8ZWxudry9GDmnw+X1kbXb+zx7XLBCnxNQZq93icAkcV7zf3HIFLACRlGhn5 v7VL3vdJJezFvhE3aU/kka56c+jvHMBeziBAPI5DpaEA+e8B7ksvksoZJvcxXQ06yglz WlYAXgEdCMn1L3x/z6SqmewYj5xos5wKi8rVKlElCeh6Fz1+hWzE1XuYzdnPGUYeJig0 rUI/3Nzl/OIznagWYbFnBLInbZzWn7pAf2gWhCRr6qkWN+1SmWUB9GkS7l1AmMn5Xi4F Tz0w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=OqaMtmt2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39813-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39813-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 m18-20020a05622a055200b0042a541555b5si812139qtx.274.2024.01.26.01.32.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 01:32:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39813-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=OqaMtmt2; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39813-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39813-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 8820C1C27A78 for ; Fri, 26 Jan 2024 09:31:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7570712FF89; Fri, 26 Jan 2024 08:56:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OqaMtmt2" 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 52B8912FF79; Fri, 26 Jan 2024 08:56:01 +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=1706259362; cv=none; b=H/vDbSk7UZJdoHuYhwml8wlP440r4sdIMOB2LQRbo+XZnrDCMwcqHXeV3Q2uXBei2elRnEEdPn/0B5KjIXGDLTSRwwwGSp+Ycp7hgfUrrGIVWw3y92w/4uEsVtcQw6Z+y15uweB/H2pJ3S8lQo5bezCyAdFW1e1UK8vfp7yYAlo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706259362; c=relaxed/simple; bh=TOkzoJKyRiNbPO8hxKraBpbBRIKmwdH5yzAALhKlwf8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=HMhNmIs8KERAfOejUFG7VQCBLc3G009lP9+FBWxZmyTU1V9dlskIfURh01+1mWEMi9fG12dgufT/0zD8iHiP+lCUsdF++2zkP+JCEZ/pazkAjT92b/TdfUxrCZt0i+3dYm9Uy2+9jU1JSZy1/28qKyjANF+CZ3o5DD6mHSti+lQ= 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=OqaMtmt2; 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=1706259361; x=1737795361; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TOkzoJKyRiNbPO8hxKraBpbBRIKmwdH5yzAALhKlwf8=; b=OqaMtmt2M9me4qgNg94fkFYxbrmzwKjwpEVUfmZQLQzznCIZZTXG6jt9 T+UiWC194dP1d0i9ATlffMqgs2mmqMn4r6FzXliiGxwZd4Aj8onqlm5Qu LNt5PTph9ghyIl7uFueW/IxwuGXnSNDhkTR5Y6K+RkdsA4tanjkgZIPJa mTDTKknHUn46auycGWpIbBxNVlW6poAPjRXPoflo4FNoiZ44OeXFvSEIa 5cq2E8a/1AV0uQId6EYNlLhxYIyxOMisJD7qpOsJ02N5K6iPI6J3LnIJi fp0Nppz0JxcE7dmwAkUjqAS2ZzOxOmeOG26P23hsqzGiAj4CcPSR2pcXI Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="9792098" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="9792098" 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:56:01 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="930309850" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="930309850" 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:55:55 -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 05/41] KVM: x86/pmu: Register PMI handler for passthrough PMU Date: Fri, 26 Jan 2024 16:54:08 +0800 Message-Id: <20240126085444.324918-6-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: Xiong Zhang Add function to register/unregister PMI handler at KVM module initialization and destroy time. This allows the host PMU with passthough capability enabled switch PMI handler at PMU context switch time. Signed-off-by: Xiong Zhang Signed-off-by: Mingwei Zhang --- arch/x86/kvm/x86.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 2c924075f6f1..4432e736129f 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -10611,6 +10611,18 @@ void __kvm_request_immediate_exit(struct kvm_vcpu *vcpu) } EXPORT_SYMBOL_GPL(__kvm_request_immediate_exit); +void kvm_passthrough_pmu_handler(void) +{ + struct kvm_vcpu *vcpu = kvm_get_running_vcpu(); + + if (!vcpu) { + pr_warn_once("%s: no running vcpu found!\n", __func__); + return; + } + + kvm_make_request(KVM_REQ_PMI, vcpu); +} + /* * Called within kvm->srcu read side. * Returns 1 to let vcpu_run() continue the guest execution loop without @@ -13815,6 +13827,7 @@ static int __init kvm_x86_init(void) { kvm_mmu_x86_module_init(); mitigate_smt_rsb &= boot_cpu_has_bug(X86_BUG_SMT_RSB) && cpu_smt_possible(); + kvm_set_vpmu_handler(kvm_passthrough_pmu_handler); return 0; } module_init(kvm_x86_init); @@ -13825,5 +13838,6 @@ static void __exit kvm_x86_exit(void) * If module_init() is implemented, module_exit() must also be * implemented to allow module unload. */ + kvm_set_vpmu_handler(NULL); } module_exit(kvm_x86_exit); -- 2.34.1