Received: by 2002:ab2:7407:0:b0:1f4:b336:87c4 with SMTP id e7csp121604lqn; Thu, 11 Apr 2024 16:27:25 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXmo9yGCD3MviFQDiEJlvJvvjP0IB6KMZ+V3nvOg9StaQIfes5XM3ni3jehZp8XcV25RRWUkPIpwDqxndw9MUWWIXAHyuuQw9kq1XmgAw== X-Google-Smtp-Source: AGHT+IGG4NmVPvyl51wzcn9eQ9HQ7+s6YgshwxG/3ZKlZkSfXMP9IiDZHwMSrDWXV3+t0BXHUImX X-Received: by 2002:a17:90a:398c:b0:2a2:d05c:95f6 with SMTP id z12-20020a17090a398c00b002a2d05c95f6mr5416322pjb.7.1712878045564; Thu, 11 Apr 2024 16:27:25 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712878045; cv=pass; d=google.com; s=arc-20160816; b=fZ7y/gZgxeC+4PqsqFsPEPHA/8MfvQL7PLr9XmAUTU7GYluPVM+ecjlDCRRw7aAhDX gnLY56wTqq3Iyh4BjNREqaC30P4xjvwQXMJ/YYS0zwnIDZOFUuygKG7zVloGX+kFSOoS PnkHicMe+hGhJsjyys6WKr22+tncUD4d15fXeMZgvdovYFToQBHXh3AXzvJozsnHKZ6e 65TFYJ/ue91M+wecZQqzAlmup8nf4IhQg2zUSmz8WIZw4VEBsvF4KVQEXxmUN9w/TNZe +ePK1Aohe06FQBuI0Q2PT9eepPHhQtD6WYOBweLt21J5M20ix1iPtuSCMqWnKFiWZDab hEsw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=saPqzjSurmxMimUcoDIYz/TWWrwnNJQ5t2nRzRoA9jA=; fh=3JffC7LlRw2JLIVe6vEr6eESLNYwaE9FK9Pymqd2JXA=; b=eOiBaBbln21arZtIG2G4m4uQ5I44KYblxzRdKQR/N8RrhvjXvCWTvRHqihApWbnoGw 5o1PDcYGIQsis28tqtf8W5ahbCH6ECATfxxcK6D4LnKZ9Fz9pyAF4reOWuUx1T1kiBaa kL9mZCvjMdi0TaCDau41v8tPTstEIkXjNCHQoSjo/fOzqNDdrj4bcN5y/yVnhUarHJl4 tftJcv7rrC4qbXFpoB/K6e+tnNEH5nMMxW8d/XeVaT6nftvAUJq1NDfU+YoWnRdc7CEY ebb7UUwdjZRZj8GEcpCd0KblJy+gNTbVlLkxc9uV7AGowxJXfmtNASHuNRCd1DtXrzpV EKrw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="h/QwSUcT"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141704-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141704-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y12-20020a17090abd0c00b002a4f14b62d6si4257274pjr.141.2024.04.11.16.27.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Apr 2024 16:27:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-141704-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="h/QwSUcT"; arc=pass (i=1 spf=pass spfdomain=flex--seanjc.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-141704-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-141704-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C7CD8288EB0 for ; Thu, 11 Apr 2024 23:18:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2C5BC481C7; Thu, 11 Apr 2024 23:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="h/QwSUcT" Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C2B9D53C for ; Thu, 11 Apr 2024 23:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712877519; cv=none; b=jTzDoHjtBLKKE8PdGjJ8Nb6VSItQxwQrQD0CYy74MdWJZXX3ynp+KkagGRlHQnoEn7DFj2l+ymGN8QU1g2Z9J+/chk05P3mUR3RLIDG+7fPAyNuxevsbPfn4LYZgNwnp5/fY9E800uCn8NeQyWYk7hktkhb3T2gR9x0kMqpIaRo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712877519; c=relaxed/simple; bh=ChViTqgL4O0iExSvoXkrz8rlXUh1To7gRM7Ht5KUpHs=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=mkvH6QKdq2+9kHPj0pdnXk4BpvK8E5XJVlJaB0YWrnhvZDLPVI+480TKy2gkzJdEPWxZ05FzOOd0qQHZvDPfmpxeBiVphCz+z8pWwZ2mwOwWWgXzH6DwjBHSeV2UvayrnD5IJqbeZ9gln35r+peNRomaotQHwtyR5EgZS5zHgPw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=h/QwSUcT; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-6ed34f8b3c8so406621b3a.1 for ; Thu, 11 Apr 2024 16:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712877517; x=1713482317; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=saPqzjSurmxMimUcoDIYz/TWWrwnNJQ5t2nRzRoA9jA=; b=h/QwSUcTAknLsH0caevy7UKRPMtWKy6/z7ghO5vniGVd3mm3HU6XDtnhVf2db15dfT F0VN/DcHUNszYK1VXwKavgO0HnsJMqRa9geE66u1BClVgQWZAalgxxaB1xS2Wz6413dA BgXqdTsTY5MUhGAFwAF3jFnOzkr89SuXllbKF+026xVY78ElHvshqPNa+wjQEhvbJizb I8+xHXxydnOZC686bzB6g0bBria+OFKJm7pk26UGAzqJzqikJm6wkH88wZrmZ5/3BH3J pRwvy2Nttd9uhWH10rTJD4037xLONIWW6jdcfLtbfRuOp5QzUQY7CqWzxl/yyFsubVhH 9ipA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712877517; x=1713482317; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=saPqzjSurmxMimUcoDIYz/TWWrwnNJQ5t2nRzRoA9jA=; b=JOT8+4mSMvPwb3gQBmQekxnyQ17MtMMmKIgesrsqCJWbxFWKFZsoDgEQJc/VFOvz55 mQua4qghW8pZQpwgEZKt34Lgs9vf9Pk/pBQO6CO4Io1UcCTBu2J2xuMjmVxUoEmIAZS8 zuvrx+PK8d0mhSDqFoKHWAqRpLvIh+fbmGLgGplHruhMhkKZkynSXf+rlWbMQEtOGB2l F5NQ5ZHG3FvFRViiPIB1KhsTK8Bqx2X6c0060xpOAnAcydwY/e4aLmoi4Auud/kwyCKz cUcul47kJdau8VPWgGpPKdzqKGE+2VtgP8gy9WDQltFpAuNFAx4TMuvgEJYEH4Q8sSjH Y2iQ== X-Forwarded-Encrypted: i=1; AJvYcCUpPkDYchgDzDd2MWngVTOi9weSrgYRJ9BFuQtcVcta6b8RQ30W9V+fTSH9WQm/q/eWsb7iyFtwaLk7xEQuyMWGqFLmF+tNxzC+Tw+0 X-Gm-Message-State: AOJu0YwE/PoyVGAKhV4T9Xj0s4r5TaNDHrnXcHArPJhuY0x/QHmAX3Xz 6Qu7SuztwhE679siqwLdM3aBibE8BiwCDJAcQMvB5whoAYvWHXbeG/qh/S7AHquAqtRHLgL8TQK GSg== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2d17:b0:6ea:c2e5:3fc6 with SMTP id fa23-20020a056a002d1700b006eac2e53fc6mr40035pfb.4.1712877516535; Thu, 11 Apr 2024 16:18:36 -0700 (PDT) Date: Thu, 11 Apr 2024 16:18:34 -0700 In-Reply-To: <20240126085444.324918-41-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 References: <20240126085444.324918-1-xiong.y.zhang@linux.intel.com> <20240126085444.324918-41-xiong.y.zhang@linux.intel.com> Message-ID: Subject: Re: [RFC PATCH 40/41] KVM: x86/pmu: Separate passthrough PMU logic in set/get_msr() from non-passthrough vPMU From: Sean Christopherson To: Xiong Zhang Cc: 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, 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 Content-Type: text/plain; charset="us-ascii" On Fri, Jan 26, 2024, Xiong Zhang wrote: > From: Mingwei Zhang > > Separate passthrough PMU logic from non-passthrough vPMU code. There are > two places in passthrough vPMU when set/get_msr() may call into the > existing non-passthrough vPMU code: 1) set/get counters; 2) set global_ctrl > MSR. > > In the former case, non-passthrough vPMU will call into > pmc_{read,write}_counter() which wires to the perf API. Update these > functions to avoid the perf API invocation. > > The 2nd case is where global_ctrl MSR writes invokes reprogram_counters() > which will invokes the non-passthrough PMU logic. So use pmu->passthrough > flag to wrap out the call. > > Signed-off-by: Mingwei Zhang > --- > arch/x86/kvm/pmu.c | 4 +++- > arch/x86/kvm/pmu.h | 10 +++++++++- > 2 files changed, 12 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/pmu.c b/arch/x86/kvm/pmu.c > index 9e62e96fe48a..de653a67ba93 100644 > --- a/arch/x86/kvm/pmu.c > +++ b/arch/x86/kvm/pmu.c > @@ -652,7 +652,9 @@ int kvm_pmu_set_msr(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > if (pmu->global_ctrl != data) { > diff = pmu->global_ctrl ^ data; > pmu->global_ctrl = data; > - reprogram_counters(pmu, diff); > + /* Passthrough vPMU never reprogram counters. */ > + if (!pmu->passthrough) This should probably be handled in reprogram_counters(), otherwise we'll be playing whack-a-mole, e.g. this misses MSR_IA32_PEBS_ENABLE, which benign, but only because PEBS isn't yet supported. > + reprogram_counters(pmu, diff); > } > break; > case MSR_CORE_PERF_GLOBAL_OVF_CTRL: > diff --git a/arch/x86/kvm/pmu.h b/arch/x86/kvm/pmu.h > index 0fc37a06fe48..ab8d4a8e58a8 100644 > --- a/arch/x86/kvm/pmu.h > +++ b/arch/x86/kvm/pmu.h > @@ -70,6 +70,9 @@ static inline u64 pmc_read_counter(struct kvm_pmc *pmc) > u64 counter, enabled, running; > > counter = pmc->counter; > + if (pmc_to_pmu(pmc)->passthrough) > + return counter & pmc_bitmask(pmc); Won't perf_event always be NULL for mediated counters? I.e. this can be dropped, I think.