Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1618345rdb; Mon, 2 Oct 2023 15:50:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHb2mnM5MVDfdHR/QnrFTVqQFYYkQprWwI4qBkDOxUn2SSy9LY4xs8ATQEbCrbSpY8YuA9C X-Received: by 2002:a05:6358:9042:b0:139:4783:5140 with SMTP id f2-20020a056358904200b0013947835140mr15064136rwf.16.1696287003304; Mon, 02 Oct 2023 15:50:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696287003; cv=none; d=google.com; s=arc-20160816; b=TJchFLBo0RM/Vq/+XRXVPonoQPlyDRxcejxd+jFMkKHPWBzQQ2b4pEdYtfwCHaE7/0 f5oBMg2qvtd4H3hVMExpxHuVffkC6nivRNywnTHuKHNoaMQvZEEv/RUo09qYgNunvYpM UHLHSGXuZLszddG5Z+r/CoLYl1CPDq3i7XtRShSOkAOz4RbRxWvvL06LUxe3vyt2Noaj JY//rJtW1RG8m0pC9KxGS5htkc3KxLizNJt4UsroD1JvdrA0gQfeS80wsZ9ldfBNgM79 ES6jQOVphdQnX6G/+jOth3obE/CqorUZ4zISOLjYWhqgOHwRaPoUzECyqsZupY7iCI6K BEiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=WcmjJranJU9dHmKZgwi11TJfqlRgTzZNCx/vVbaZ/W0=; fh=wP52kTW3jzpJRTsaVbptZ4zNe9AOh+6X5ISU/33irl4=; b=F7MRXU8ie6owFy8F9DT01egbPq2hkcNpeAoohWPq3Bj07ogvHIqWs0yZV8qR2a84Ck HzzbFK5wmtNYgN+JmiiJbJ/KeHKD1NGT+JDMxYqNuGxE76Ejbd9/9UJ7dQIBuLUYF5ck J1AZeaDk7OD2YSdX1V7IcALPSOISC+zDJV2NoPv0rp8WQ7QlU1QRVRtqoSXxEiqvrgEY 3ICTwtEob77oIBzs9tnSVR21PJaAB6XfNL1sR8rU7y93wT2zc0WxTtVWTStTT6NfRPcq C+LMrP6kU/XQ3aoFYmz4bRmIx3MDoz9qFnOReg9Su32/TEbhFE0eu6/SAx3Wozl+lsx4 zQug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WRCQdQGH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id f16-20020a63e310000000b005740e906e46si23951900pgh.358.2023.10.02.15.50.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:50:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WRCQdQGH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 229E2801CC8E; Mon, 2 Oct 2023 08:23:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238066AbjJBPXf (ORCPT + 99 others); Mon, 2 Oct 2023 11:23:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237928AbjJBPXd (ORCPT ); Mon, 2 Oct 2023 11:23:33 -0400 Received: from mail-qt1-x82f.google.com (mail-qt1-x82f.google.com [IPv6:2607:f8b0:4864:20::82f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7ED3B7 for ; Mon, 2 Oct 2023 08:23:30 -0700 (PDT) Received: by mail-qt1-x82f.google.com with SMTP id d75a77b69052e-4195fe5cf73so438171cf.1 for ; Mon, 02 Oct 2023 08:23:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696260210; x=1696865010; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=WcmjJranJU9dHmKZgwi11TJfqlRgTzZNCx/vVbaZ/W0=; b=WRCQdQGHTZRwMsM/W5bx9E3lku+poVB/wDA58277PG8jQwqVtE0Cbu/XEumKa0Lps6 0J5eKYADoXN+vUWAvYxnXH9dSe4nG6LkHrwJvH4g3dvbUs3ntyk3j+7bD4m1363WSjQw tzMSSbs1cPT9kNtswcAg70HcFBcDugUv3awR6lRzA1Zhb372xG22TwZLTPG5LvpbV0re DAJjmCby8mqQN5R4wfdRZOZYSA+zRRKPX5sAawG09qginICkco9KeCzdWAlF7AF55pHp QFxwtSRlUXbXAEweNyj5a1aqSq8g307bIk0fcPIk9FLhafs5QkCgVVDF2jPq3ny0zh5f DkcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696260210; x=1696865010; h=content-transfer-encoding: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=WcmjJranJU9dHmKZgwi11TJfqlRgTzZNCx/vVbaZ/W0=; b=ctSdFV+PoXWhnSiJZ5oEiXBlPT1Lkv+my/5rA6SUUeOldulB4sO5yhQZEELeLw3xvA nAQQre9tKKq5M1hwV/I1VdT2ssLnEXpXy12pfgbEFkAyQOK4JuTqktq0IQ1RHHInphD7 NIh9Rc/J1pGjfx5X7M7EI6LYiz/mBhJJz30Ghyzcvl5Jx7z2vcUGa5LXp2AsiPWPa1sY 1ZFe5N2+ti1YG7VSy6TP4OZQEoj50N793hXMNo8plYU9ehGZ/LpoZnvbR90qjZ66020d +KnKVit1moINe1SBbg61aF8envRXcrYI6BReQMRX/H77OSD3h1vxPeCfbP6qiguqDCyW ZLZA== X-Gm-Message-State: AOJu0Yzd33tACPorZobi74A315+budgckniFhGmVienKGDFsg0tg4ocr qFxI+x57KsrOSiOc4giv6kjuBYAz0/K+unQg4NPEpQ== X-Received: by 2002:a05:622a:94:b0:417:9238:5a30 with SMTP id o20-20020a05622a009400b0041792385a30mr354168qtw.29.1696260209711; Mon, 02 Oct 2023 08:23:29 -0700 (PDT) MIME-Version: 1.0 References: <20230927033124.1226509-1-dapeng1.mi@linux.intel.com> <20230927033124.1226509-8-dapeng1.mi@linux.intel.com> <20230927113312.GD21810@noisy.programming.kicks-ass.net> <20230929115344.GE6282@noisy.programming.kicks-ass.net> <20231002115718.GB13957@noisy.programming.kicks-ass.net> In-Reply-To: From: David Dunn Date: Mon, 2 Oct 2023 08:23:17 -0700 Message-ID: Subject: Re: [Patch v4 07/13] perf/x86: Add constraint for guest perf metrics event To: Ingo Molnar Cc: Peter Zijlstra , Sean Christopherson , Dapeng Mi , Paolo Bonzini , Arnaldo Carvalho de Melo , Kan Liang , Like Xu , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Adrian Hunter , kvm@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Zhenyu Wang , Zhang Xiong , Lv Zhiyuan , Yang Weijiang , Dapeng Mi , Jim Mattson , Mingwei Zhang , Thomas Gleixner Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Mon, 02 Oct 2023 08:23:46 -0700 (PDT) On Mon, Oct 2, 2023 at 6:30=E2=80=AFAM Ingo Molnar wrote= : > > > The host OS shouldn't offer facilities that severely limit its own capabi= lities, > when there's a better solution. We don't give the FPU to apps exclusively= either, > it would be insanely stupid for a platform to do that. > If you think of the guest VM as a usermode application (which it effectively is), the analogous situation is that there is no way to tell the usermode application which portions of the FPU state might be used by the kernel without context switching. Although the kernel can and does use FPU state, it doesn't zero out a portion of that state whenever the kernel needs to use the FPU. Today there is no way for a guest to dynamically adjust which PMU state is valid or invalid. And this changes based on usage by other commands run on the host. As observed by perf subsystem running in the guest kernel, this looks like counters that simply zero out and stop counting at random. I think the request here is that there be a way for KVM to be able to tell the guest kernel (running the perf subsystem) that it has a functional HW PMU. And for that to be true. This doesn't mean taking away the use of the PMU any more than exposing the FPU to usermode applications means taking away the FPU from the kernel. But it does mean that when entering the KVM run loop, the host perf system needs to context switch away the host PMU state and allow KVM to load the guest PMU state. And much like the FPU situation, the portion of the host kernel that runs between the context switch to the KVM thread and VMENTER to the guest cannot use the PMU. This obviously should be a policy set by the host owner. They are deliberately giving up the ability to profile that small portion of the host (KVM VCPU thread cannot be profiled) in return to providing a full set of perf functionality to the guest kernel. Dave Dunn