Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp849950lqt; Fri, 19 Apr 2024 12:14:39 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUguGg0wgdHCxiyJbG2OXWKOpJXCnFIyOdnyAYm0DTBzmAnikHTDg0JjudLBqTaoz7Hu8tbshCBTMTrzA4X8mlmZtIkNo/TlTw6atPI7w== X-Google-Smtp-Source: AGHT+IG9SIS6CbTDC6IQsVkQUddBXZGmoOhpFQ77i/Sq6tXkIuuG1sAkxYSQfhI3Xt6Sg1ou5h2f X-Received: by 2002:a05:6870:8309:b0:22a:582a:9bcc with SMTP id p9-20020a056870830900b0022a582a9bccmr3401593oae.53.1713554079198; Fri, 19 Apr 2024 12:14:39 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713554079; cv=pass; d=google.com; s=arc-20160816; b=hY7GbaXW4js21jEA7mh1j0rCInGYcY+s0T3SvEa4A2VlQW6i1eu2LmzbgE5xAj/gEm MEdGoGlRAgyzWa2VMOD45VzhopE4E0BAXz3EU1l+HFVg/VtZHjUjAzl5GBkAR5xOo8pX NU7ZhTOdB0pO8DpiNJ/oEOd6x8YcI74RXoqWChcmsEN6ap/y67LrRCASk7w5B+7x2GJa tKvneFhMAoxyMmLpFFBpeRMp/JJiRQzNkoitkzDPkAEzRaEnMM+nGOhY0u8AsCVBuwv2 PBBnYXyilQOS4wC6JfsYX9bxeC9O2KLn/wLhvvB6BHZPdnJ4XOJBeGlLMK16pwGktIsT T98w== 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=LxyLjfyND/X0CfR1qvIubJS+urbDCxyrK24QGGBvcRg=; fh=k7rTsYBWtZrGIxleRjfasvQiaBLxbME+orjO6qDVUfU=; b=n4ihrYhNUQUjiiD45NEuUs/LwNoWr+XMGJTur2tQ48gG+9t71eBM436tl1XhMOpGC8 QYQNQ1DZnvpkzczpJZ8ECeniJQm9iCHXLdJC/QRB1UVRPihTmUbVfEplNrMkO0emppCQ vLdob+ESJek6SJ3Vm5SYPRUjKpS2RDBsRx3+U7Q0auk4x9tg+f2pIOi5Bqgub3a+Beng huQ/CZUw2W1MzIHt9lOo/middtNhtIHz9D9omb7ao5NiO+rvXXu/Bv6K7k7sjSLKZMj4 Z4fLjz8wSi095wyEOTTNeLHSnlVa88eIvtt0tSy5ulPCWGeg5pfOyNWYedyjYCUDTQZy y78A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Phyt+OmO; 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-151896-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151896-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. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id y19-20020a63de53000000b005e42b5db0ffsi3638510pgi.40.2024.04.19.12.14.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 12:14:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151896-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Phyt+OmO; 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-151896-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151896-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 B24D3281688 for ; Fri, 19 Apr 2024 19:14:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8312013C909; Fri, 19 Apr 2024 19:14:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Phyt+OmO" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.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 2CE7313B284 for ; Fri, 19 Apr 2024 19:14:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713554066; cv=none; b=ZmsA4fW3qWJzZ/CxO1gQz7m7qg6Rys2YGoSDbeqU6tyl+PWDUgOu9omxqa6A8b77kp2U2Y0Dq5APnsc3PdwpzwNSW8ON5LBtCAG3LumtN06toSpd6mrAoK0x2yuOF0r6mr+GKFYcv7MPPDfx9c9lWrruPjeShYz+WXb+6epTcjI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713554066; c=relaxed/simple; bh=ghHRvfsnLZoBuD+thj2tzA2nIrRJDK62IHkGCKIFt9A=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Xp/ENG26a+w2AjzLyjohdnz73C+g63Ot9/8eUsWPiugqfD2lhyUc7qGPJ+31tu7n1mclhtEiKSBlnt72NUuHzYtgzMMhifeClm1N2Z/ooR/Y8Bn/p2pf1PQpdCoa6YuBc66Yl9baTEmlRCXQfOv8t6ZSZ5ijqkhSRmM/4krCAGs= 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=Phyt+OmO; arc=none smtp.client-ip=209.85.219.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-yb1-f201.google.com with SMTP id 3f1490d57ef6-de468af2b73so4197288276.0 for ; Fri, 19 Apr 2024 12:14:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713554064; x=1714158864; 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=LxyLjfyND/X0CfR1qvIubJS+urbDCxyrK24QGGBvcRg=; b=Phyt+OmOLRhTdZkGxZSe2A7lyD8q0bdQAvdmS0mUtCeCjk/hEm+PpA70c7g9yvOR+9 NcvK1QiLKQJJDu1IVCizbI3tFm3Ttq83m7aHboMwtXJMJUnsA/ZTXz9GY6RcCAQe1G4R ltj3kBgL73AE0WbAKKB/NTeHlfZy3nWGmIViEAvV7/SJWTj7z77jzH8jdyvNqrf4YuG0 2aXk+90jUYDyMMMGJSM9GTFpWginoX2BH99C8G3qHT5xYkb8wSOyfscR50xbefu1Ckcx 3thmYxD8qDOl+Iyaah8Z2PGvMijJSwbf067mBjDmQCZz9adnirJPAcZxptWV3VkIKNn+ BiJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713554064; x=1714158864; 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=LxyLjfyND/X0CfR1qvIubJS+urbDCxyrK24QGGBvcRg=; b=A2T/lxKhKbN5JYSugYHhLR7xmUkqvAEeVJRHgtdDZv+Qpud9/S4A5GE7yTIQmMXxPR 7XV/p2mOdSqCx2U4aXqqN4F/k6caDi+1VjS5syKCujFJo6e6ouIvCAYs8xk81DVoqINB JSKB7M1jWqNmgkoEgCplbOmb7VJeslC+Xe5YfEAJPriw4P8SXSM15Gkn7+irkXYZJdRL nKB0RReXGeGvq+tAqLLnfXBd9Dfv1WrtvO77ysygMPihcVy40jYgvxdDW+waZ+iFXOyk DfcPNErA7z+Dl+qGzrvZ5ElBZN6LGXoQsf1OiLN3fIw2VxC8Ab24+wMbPv/BLKSnTTre 8vEg== X-Forwarded-Encrypted: i=1; AJvYcCUiXlGsRVSOPpu+OPLn+D+n+ZRLtNgxgaCir42ju/ztOW5HPlzc8504ggsckCP5xA1w+bdtXYEjZV0Tac3UuBQNuhtGgAgBzW3LONvC X-Gm-Message-State: AOJu0Yy71xGadjPXkZcBiR4x8awPlhN6DYYuIRKD/wB+SXH1JXTbq6Pu QmQ2iwFf6IY/SUhD0hkfEiLjiQoyr0kfAf0+y9klomzZ2zgu08V949x0udE7OGGHZ55WPauICUI dlQ== X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6902:c01:b0:dcd:b431:7f5b with SMTP id fs1-20020a0569020c0100b00dcdb4317f5bmr824560ybb.0.1713554064161; Fri, 19 Apr 2024 12:14:24 -0700 (PDT) Date: Fri, 19 Apr 2024 12:14:22 -0700 In-Reply-To: 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> Message-ID: Subject: Re: [RFC PATCH 00/41] KVM: x86/pmu: Introduce passthrough vPM From: Sean Christopherson To: Mingwei Zhang Cc: Xiong Zhang , pbonzini@redhat.com, peterz@infradead.org, 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 Thu, Apr 18, 2024, Mingwei Zhang wrote: > On Thu, Apr 11, 2024, Sean Christopherson wrote: > > > > > > I think we should call this a mediated PMU, not a passthrough PMU. KVM still > > emulates the control plane (controls and event selectors), while the data is > > fully passed through (counters). > > > > > Sean, > > I feel "mediated PMU" seems to be a little bit off the ..., no? In > KVM, almost all of features are mediated. In our specific case, the > legacy PMU is mediated by KVM and perf subsystem on the host. In new > design, it is mediated by KVM only. Currently, at a feature level, I mentally bin things into two rough categories in KVM: 1. Virtualized - Guest state is loaded into hardware, or hardware supports running with both host and guest state (e.g. TSC scaling), and the guest has full read/write access to its state while running. 2. Emulated - Guest state is never loaded into hardware, and instead the feature/state is emulated in software. There is no "Passthrough" because that's (mostly) covered by my Virtualized definition. And because I also think of passthrough as being about *assets*, not about the features themselves. They are far from perfect definitions, e.g. individual assets can be passed through, virtualized by hardware, or emulated in software. But for the most part, I think classifying features as virtualized vs. emulated works well, as it helps reason about the expected behavior and performance of a feature. E.g. for some virtualized features, certain assets may need to be explicitly passed through, e.g. access to x2APIC MSRs for APICv. But APICv itself still falls into the virtualized category, e.g. the "real" APIC state isn't passed through to the guest. If KVM didn't already have a PMU implementation to deal with, this wouldn't be an issue, e.g. we'd just add "enable_pmu" and I'd mentally bin it into the virtualized category. But we need to distinguish between the two PMU models, and using "enable_virtualized_pmu" would be comically confusing for users. :-) And because this is user visible, I would like to come up with a name that (some) KVM users will already be familiar with, i.e. will have some chance of intuitively understand without having to go read docs. Which is why I proposed "mediated"; what we are proposing for the PMU is similar to the "mediated device" concepts in VFIO. And I also think "mediated" is a good fit in general, e.g. this becomes my third classification: 3. Mediated - Guest is context switched at VM-Enter/VM-Exit, i.e. is loaded into hardware, but the guest does NOT have full read/write access to the feature. But my main motiviation for using "mediated" really is that I hope that it will help KVM users grok the basic gist of the design without having to read and understand KVM documentation, because there is already existing terminology in the broader KVM space. > We intercept the control plan in current design, but the only thing > we do is the event filtering. No fancy code change to emulate the control > registers. So, it is still a passthrough logic. It's not though. Passthrough very specifically means the guest has unfettered access to some asset, and/or KVM does no filtering/adjustments whatseover. "Direct" is similar, e.g. KVM's uses "direct" in MMU context to refer to addresses that don't require KVM to intervene and translate. E.g. entire MMUs can be direct, but individual shadow pages can also be direct (no corresponding guest PTE to translate). For this flavor of PMU, it's not full passthrough or direct. Some assets are passed through, e.g. PMCs, but others are not. > In some (rare) business cases, I think maybe we could fully passthrough > the control plan as well. For instance, sole-tenant machine, or > full-machine VM + full offload. In case if there is a cpu errata, KVM > can force vmexit and dynamically intercept the selectors on all vcpus > with filters checked. It is not supported in current RFC, but maybe > doable in later versions. Heh, that's an argument for using something other than "passthrough", because if we ever do support such a use case, we'd end up with enable_fully_passthrough_pmu, or in the spirit of KVM shortlogs, really_passthrough_pmu :-) Though I think even then I would vote for "enable_dedicated_pmu", or something along those lines, purely to avoid overloading "passthrough", i.e. to try to use passhtrough strictly when talking about assets, not features. And because unless we can also passthrough LVTPC, it still wouldn't be a complete passthrough of the PMU as KVM would be emulating PMIs.