Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp922104lqt; Fri, 19 Apr 2024 15:03:40 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW8F4ojwW1TPDNbQuyw6wPtg1INFKurpa2Kl66I6E64dXGpfAcu11exs8s1r9W52kz96l6j2+eFcSK/aXTe7acpAeb1NC+Ikb3+RpiVZw== X-Google-Smtp-Source: AGHT+IHQS89sImyaW6qRFKhYS53R7ozRBv6ZyGyaD8Gm3EDPohC1nG94ESsgYWRpa9nCQNet0/36 X-Received: by 2002:a17:906:2997:b0:a52:6fe5:938b with SMTP id x23-20020a170906299700b00a526fe5938bmr5689750eje.26.1713564220810; Fri, 19 Apr 2024 15:03:40 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713564220; cv=pass; d=google.com; s=arc-20160816; b=WdsuNfET5y2r/ZGoKPE6F/XpCMm8y4etHMUBrp0z14LE48kSHNBsDn63F3o7bZcvbL qSsR5kS95wDpiUuIs6bcjfcO/M/wYO9C7jZLKge2BoyvvLTSwd1vNaADRM+y2joCdvEx 3QJ1RrBQtP6M/2e7kTlfJ69yGVZE0topKTKNe4cVR74UhRQqwhJwjpQGil7nmxoG1ntz nwqtzHR3kyZ8oNjeEG/5ROfA7IAtl6Sy4MQ98Aq00IwUdWI53wljPBTTa75CTMfhjDVc zX+9S5kGHavriZ794QdOJdjvx/vHzsXlQDoHijv+RhrKMgwVlIJ5FFluXuiwCxJzflGG AZsg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=fPM7E5V6o141sK0f0dMZ+PfvZ9fH+BP0EjEziH4VhA8=; fh=BT/yVCNjCrs98POIPFTv2p91aV7PPrgCMwOBDeujQPg=; b=Y8r1RY97JboDzPZ1Mm8yXIsi3Dgqv/m1MSyCLmBQ4BoOtvoyM/Z0RsEOLqF9GLKGXW Xy+0AFPKjO30fcLuiE0b2djxhmdYc6+T+NBroP0YUx9Zt1cFXgwEWLuBjJ0EDsUDK4P8 mgfbcMLy4+W0BBgI/nHghGqX0qzBLeTZDpZmHwMrQ3+HfV+wYBqnYyY0PpKnragREdyc yRen6eEU7WOHVFjwMmUlFtF8pYG1krw0VRjaO35mDblA5zcOEQz+nHzNWjVXEQn7oSUL 8PrlC4k9PGTS4lbM4qS386rGukb4AdoiWDIqstA2+vmGb+qOuZm26xL/Rn5kbPGBjPen YxEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GuATQqUW; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-151985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151985-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id h22-20020a1709062dd600b00a523af4f5a7si2536721eji.667.2024.04.19.15.03.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 19 Apr 2024 15:03:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=GuATQqUW; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-151985-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151985-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 607D61F218CA for ; Fri, 19 Apr 2024 22:03:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CBE4E13D294; Fri, 19 Apr 2024 22:03:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="GuATQqUW" Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 1F0C113D24C for ; Fri, 19 Apr 2024 22:03:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713564206; cv=none; b=dq8Ll/qdTudNpu1HB13VFx+QXmHoWemEYUgSerBJAeAaB9JbFbOkJ9FZqkgSxqrgFIAVZSVR6LP0tdv09RUbgIUwMgSYpoiVh/ViLATkMF7dxRNUo88Q8B8HoiYHgn3aqyCweY9PPJsk6fqzELfbMeFjrARYL1HO4CWpfGtrn8Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713564206; c=relaxed/simple; bh=Q/Zh4Phu3kMJZN8fjVTRc3aiOk1qAnHvnKyLpI/2Y4A=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=mdTmL/h+CD71Kslz/tNIhY2gAW+GybMp403ZEufErZDJR1Lo+EElAF9vJ2/LDHmOHYPMTidD8UeQaTcRmMjhW58FyMX4iu8ZlKu7enmtblpK0sBSi23kSB7TMM2ziNhNbxxGAkCJA86nxDvvaxvZH1CWPVZA+GnDrkNTCWi8SSw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=GuATQqUW; arc=none smtp.client-ip=209.85.208.42 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=google.com Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-56e78970853so5703393a12.0 for ; Fri, 19 Apr 2024 15:03:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1713564202; x=1714169002; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=fPM7E5V6o141sK0f0dMZ+PfvZ9fH+BP0EjEziH4VhA8=; b=GuATQqUWiwG1eUfs4DKhOcSeJuMl+U18hqa0DM7T10yr42EjEYFAngxc3rMjZBfDcp VyPa0TRuzdxejmQKvSybH0ssnIBaWC/xS6EmkW8PYemSNQ2tpej3YAfPvMpL30ty7zQL 4f7VQMgUcrU3+CU14FzZfNh4Mtdesg/EqyTUNipPjvX9Etz57rzAXxMsNJQF7ASFUL64 T88gMWBRkFN6bZpH4K+Mr3eTay7ech0itguD+sqAkzBWGJQntV/aGsRYZDtCvwE+/zwF p3J5CcKD7+U2Hp0+kUNTxPDrvCf9PfS6TwBbLRAq7sFna/uvoirA1shCVk+omdqjLwm1 01hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713564202; x=1714169002; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=fPM7E5V6o141sK0f0dMZ+PfvZ9fH+BP0EjEziH4VhA8=; b=Kb8rGGMp2FFoFkZzqRQ0wLlR/2JDWz0HN7/9BlhkXJeCV+8gzTrzQ5KR+0HbuniUAh rjeUcJv3k9gsSWO/3ENlNCl5sbH+OvZ37gJrsxowYFEBPArJeoZJImDTYAGwzSUzX+uQ CZpRdhvRmn6qFUz09yCKTeBLHw8+wOI+AeBxvCdF1Jz6JTplWI88KcWRZALIkO3ul32X t4MYCn0BEToZDVVZJNfo5c/65A0V7ENx9/aTYwAu8e3AWYwB0Hfdc3PZkji+vfNcylCp SBTqMUPBd628avnbM1+ve5YjW7QPmsFVq/gf5ZEOG6UYzu4WbQNRhwVNAxlpuUvaEHqo AyUg== X-Forwarded-Encrypted: i=1; AJvYcCXvVuiem4n/3CjUcFzsaVajbHJwUrbW84kvsuDICcX7fShFvPOQF1ariZH2gybMkg3QDDungS7neqTFW2Gen2KzHxVV4MrxIEwCla95 X-Gm-Message-State: AOJu0YwwI+rrLFubntcbMtAtBsK4LBXfGnqd6wy3BiXty/N/prom/GVY oXhlHUXkIGRcFx7HKZVpxLKxwn9IsEodcSywBgQFTprcFDNERlOZY+78ERf4KDfghyu90ix6DKr GlOnwpnktld3Lm0pnaIJDthdxpJQzxD9hkkcC X-Received: by 2002:a17:906:c34c:b0:a55:6d17:6fbf with SMTP id ci12-20020a170906c34c00b00a556d176fbfmr3229721ejb.5.1713564202210; Fri, 19 Apr 2024 15:03:22 -0700 (PDT) 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> In-Reply-To: From: Mingwei Zhang Date: Fri, 19 Apr 2024 15:02:45 -0700 Message-ID: Subject: Re: [RFC PATCH 00/41] KVM: x86/pmu: Introduce passthrough vPM To: Sean Christopherson 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="UTF-8" > 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. Sure. In fact, "virtualized" works for me as well. My mind is aligned with this. > > 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. Understand this part. Mediated is the fact that KVM sits in between, but I feel we can find a better name :) > > > 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). Oh, isn't "direct" a perfect word for this? Look, our new design does not require KVM to translate the encodings into events and into encoding again (in "perf subsystem") before entering HW. It is really "direct" in this sense, no? Neither does KVM do any translation of the event encodings across micro-architectures. So, it is really _direct_ from this perspective as well. On the other hand, "direct" means straightforward, indicating passthrough, but not always, in which KVM retains the power of control. > > 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 :-) Full passthrough is possible and the naming of "really_passthrough" and others can all be alive under the "direct 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. I agree to avoid "passthrough". Dedicated is also a fine word. It indicates the PMU is dedicated to serve the KVM guests. But the scope might be a little narrow. This is just my opinion. Maybe it is because my mind has been stuck with "direct" :) Thanks. -Mingwei