Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp630481rdb; Fri, 26 Jan 2024 06:16:50 -0800 (PST) X-Google-Smtp-Source: AGHT+IGT13KiH3wge6vxVvx7KIjgUwsGBp8S/02A31ZcZXHzdpTq7Bj/rPaU1Z057mUt/0jCUy/2 X-Received: by 2002:a17:902:cec9:b0:1d7:4dfa:cbbe with SMTP id d9-20020a170902cec900b001d74dfacbbemr1163554plg.44.1706278609888; Fri, 26 Jan 2024 06:16:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706278609; cv=pass; d=google.com; s=arc-20160816; b=nwkcmpoeWpRHHL1lsc9k7ZuQmW1bgwc9Z8wZC7sdpogBCGRo/kPCe+P+n98hcE87r7 MJtbHJfCOGzS4WMStv3Vdu1oKwu0VTbERl30NR+e8NmNpP6EIw6+Cqhq2W9O9/Rzi2cS MdLH7aqljDJGjfDoHY6ul0sW1/wYrHwqDq/4W1yLs9yZEqTfHtgJg0zexNrRelzeSo3b 90Qv5ZxncSqUbpxNbUvTCCvQvr7hKLatsNavwp8xXfU3UT8h+nn9csbXiuo2yWN99W7D XLd3wFEskuk8e8v+VjrmCZkGnPbGWQVEJ8RcKPVoH2fAgF4fWafbUhoH/fyP+UG/Zr1+ eTPw== 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=cNq3YojmnXWJrGG7IqBX1LxO7ppJmSArGe2oCrEmojo=; fh=fKQXo0qMcal6BogvSG9bxyWEWsAUcPVWLMmdMql1Nx4=; b=M4y46clINFuEMgcN1XFzTQEk7fdorosDmlxBAzDC6I9IBmRul2OF7dl2TUeLdbywpD cxlXfmERBqi0kEZG1T88fuRiUWpVmL4SRR6pBqNZLcGovnwCgevAoUyh/lxJ9iXN9rH/ snBfQ7AUa8ZU8TmvBFMpZzH8Q/1TZyQs6OBGn4WuVLm4Zsc9SsLrdeTvE9vsQCjjX7+u qWjklAvIbyysM+omh4A1aWEDKZzLduuiguH5YTRHD5pArviTuuRCL0MuOt6By9L/wvHs t7EuUOjUAtcoEsr95WfZ/jtDStRVmFwsMxOxHlRkgmIQzbt5Ss5slMraIDVNhKq2aupO Yjbw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K4PbeDQ3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39860-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39860-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. [147.75.48.161]) by mx.google.com with ESMTPS id l15-20020a170903244f00b001d7162d62d2si1219059pls.283.2024.01.26.06.16.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 06:16:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-39860-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=K4PbeDQ3; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-39860-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-39860-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 5D4DAB2C1E9 for ; Fri, 26 Jan 2024 09:48:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 47E5D151CCE; Fri, 26 Jan 2024 08:58:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="K4PbeDQ3" 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 2D64145C1F; Fri, 26 Jan 2024 08:58:50 +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=1706259531; cv=none; b=Otexncu2M/LOj3YmQG9mL2LKZfCN+mz/WkXjN/g/NjL7GJVOHtlZrFFWYDyZpEmQD2/L6idCRENjInGXXQ6+1Wz5sa1bK6DQFV+XOA7MMJv++n/EW9eg8EMwwv7v23QG31zePAH09UNSn/BT2I64em9FtQqZiLcg0Ou5HBCnN5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706259531; c=relaxed/simple; bh=p9S5KED8WuoSV/G4Ddkqt0eIdsqyB+al3BlwWfdDgS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=djgL9uzKijQOo2IdQ4BLZKU2oQJ2fPtwNiFNlNJInzI5p7brX1cyuZWKeRHMp+OgYFOECJGfNC8PsHfZNQ4YkOGeNvRdX86YCdfsuxWpFSOAfUkhuPrjxwKbROdc+41KQh2p03L/xMgaae9cSj1/UjJhkmeb19iPzkl+XVZZ/0k= 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=K4PbeDQ3; 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=1706259530; x=1737795530; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=p9S5KED8WuoSV/G4Ddkqt0eIdsqyB+al3BlwWfdDgS4=; b=K4PbeDQ3AelyQe/fQT9GVtXNW1i1lDeJ1pw0Bt/7RR49bBzwIelSMf// 1BOawB0WKKGSU9RjAokFgDdWpVwySfkbkh83DMdxqN7Ku1qgXo1/mR4T5 viokzlSqaIec8h3A1uLIqjQq0xGj5iaiTETTqbxu148fSZwIDrOaqu5DO GhffTbL0mME1jdri3YaPiFIJ61RbhYkH3kiOwnWXwYg5GiJSADZ2AQCfk WVHu2X+K4WVeTKYtJHc0MhLtqJqPFnpzqj0XY6ayyOLubMta5nMcDudqj w5TUUKrPZmANna/udJ90/F4AjiCGqb2BLaiEfirTh6wTuaJQcvl82UVDg w==; X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="9793069" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="9793069" 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:58:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10964"; a="930310492" X-IronPort-AV: E=Sophos;i="6.05,216,1701158400"; d="scan'208";a="930310492" 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:58:44 -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 Subject: [RFC PATCH 38/41] KVM: x86/pmu: Introduce PMU helper to increment counter Date: Fri, 26 Jan 2024 16:54:41 +0800 Message-Id: <20240126085444.324918-39-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 Introduce PMU helper to increment counter for passthrough PMU because it is able to conveniently return the overflow condition instead of deferring the overflow check to KVM_REQ_PMU in original implementation. In addition, this helper function can hide architecture details. Signed-off-by: Mingwei Zhang --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/pmu.c | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index b02688ed74f7..869de0d81055 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -501,6 +501,7 @@ struct kvm_pmc { bool is_paused; bool intr; u64 counter; + u64 emulated_counter; u64 prev_counter; u64 eventsel; u64 eventsel_hw; diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c index e7ad97734705..7b0bac1ac4bf 100644 --- a/arch/x86/kvm/pmu.c +++ b/arch/x86/kvm/pmu.c @@ -434,6 +434,21 @@ static void reprogram_counter(struct kvm_pmc *pmc) pmc->prev_counter = 0; } +static bool kvm_passthrough_pmu_incr_counter(struct kvm_pmc *pmc) +{ + if (!pmc->emulated_counter) + return false; + + pmc->counter += pmc->emulated_counter; + pmc->emulated_counter = 0; + pmc->counter &= pmc_bitmask(pmc); + + if (!pmc->counter) + return true; + + return false; +} + void kvm_pmu_handle_event(struct kvm_vcpu *vcpu) { struct kvm_pmu *pmu = vcpu_to_pmu(vcpu); -- 2.34.1